<template>
	<view class="container">
		<view v-if="flag">
			<carHeader :title="'输入核销码'"></carHeader>
			<view class="top">
				<view class="input1">
					输入核销码:
				</view>
				<view class="u-demo-block_content">
					<text>{{inputValue}}</text>
				</view>
			</view>

			<view class="bottom">
				<view class="bottom1">
					<text>核销码:{{inputValue}}</text>
				</view>

				<view class="bottom2" v-if="list">
					<text class="title">服务内容</text>
					<text class="zw1">{{list[0].proName}}</text>
					<!-- <text class="zw">XXX标准洗车服务包含</text> -->
					<!-- <text class="zw">整车泡沫冲洗擦T</text>
					<text class="zw">轮胎轮椅冲洗情节</text>
					<text class="zw">车内清尘</text>
					<text class="zw">内饰脚垫简单除尘</text>
					<text class="zw">(不包含虫户、水泥、沥青和顽固污渍清理等)</text> -->

				</view>

				<view class="bottom3" v-if="list">
					<text class="title">订单信息</text>
					<text class="zw">订单金额：<text>￥ {{list[0].newPrice}}</text></text>
					<text class="zws">实付金额：<text>￥ {{list[0].ordActualPrice}}</text></text>
					<text class="zw">优惠金额：<text>￥ {{list[0].couPreferentialMoney}}</text></text>
					<text class="zw">订单编号：<text>{{list[0].ordNumber}}</text></text>
					<text class="zw">支付时间：<text>{{list[0].verificationTime}}</text></text>
					<text class="zw">预约时间：<text>{{list[0].bookingTime}}</text></text>
				</view>
			</view>

			<view>

				<button class="status" @click="openPopup" v-if="flag2">确认核销</button>
				<button class="status2" v-else="">已核销</button>
				<uni-popup ref="popup" type="dialog">
					<view class="custom-dialog">
						<text>核销此订单</text>
						<text>请您仔细核对订单,此操作不可撤销,请谨慎选择！</text>
						<view class="button-confirm">
							<button @click="closePopup" class="button-confirm1">取消</button>
							<button @click="confirm" class="button-confirm2">确认</button>

						</view>
					</view>

				</uni-popup>
			</view>
		</view>
		<view v-else>
			<carHeader :title="'输入核销码'"></carHeader>
			<view class="top">
				<view class="input1">
					输入核销码:
				</view>

				<view class="u-demo-block__content">
					<text>{{inputValue}}</text>
				</view>
			</view>

			<view class="bottom">
				<view class="bottom1">
					<text>核销码:{{inputValue}}</text>
				</view>

				<view class="bottom2" v-if="list">
					<text class="title">服务内容</text>
					<text class="zw1">{{list[0].proName}}</text>
					<!-- <text class="zw">XXX标准洗车服务包含</text> -->
					<!-- <text class="zw">整车泡沫冲洗擦T</text>
					<text class="zw">轮胎轮椅冲洗情节</text>
					<text class="zw">车内清尘</text>
					<text class="zw">内饰脚垫简单除尘</text>
					<text class="zw">(不包含虫户、水泥、沥青和顽固污渍清理等)</text> -->

				</view>

				<view class="bottom3" v-if="list">
					<text class="title">订单信息</text>
					<text class="zw">订单金额：<text>￥ {{list[0].newPrice}}</text></text>
					<text class="zws">实付金额：<text>￥ {{list[0].ordActualPrice}}</text></text>
					<text class="zw">优惠金额：<text>￥ {{list[0].couPreferentialMoney}}</text></text>
					<text class="zw">订单编号：<text>{{list[0].ordNumber}}</text></text>
					<text class="zw">支付时间：<text>{{list[0].verificationTime}}</text></text>
					<text class="zw">预约时间：<text>{{list[0].bookingTime}}</text></text>
				</view>
			</view>
			<view>
				<button class="status2">已核销</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputValue: '', // 存储传递过来的核销码
				flag: true,
				flag2: true,
				list: [],
			};
		},
		onLoad(options) {
			// options 是一个对象，包含了页面的查询参数
			// console.log('接收到的数据为:', options.value);
			console.log(options.data);
			this.inputValue = decodeURIComponent(options.value);
			console.log('接收到的数据为:', this.inputValue);
			if (options.data) {
				try {
					this.list = JSON.parse(decodeURIComponent(options.data));
					console.log('数据列表', this.list);

					console.log('状态为' + this.list[0].ordStatus);
					console.log('id为' + this.list[0].ordId);

					if (this.list[0].ordStatus == '已完成' || this.list[0].ordStatus == '已退款' || this.list[0].ordStatus ==
						'已取消') {
						this.flag = false;
					} else {
						this.flag = true;
					}
				} catch (e) {
					console.error('解析数据列表时发生错误:', e);
				}
			} else {
				console.log('未接收到数据列表');
			}
		},
		methods: {
			openPopup() {
				this.$refs.popup.open();
			},
			closePopup() {
				this.$refs.popup.close();
			},
			confirm() {
				uni.request({
					url: 'http://localhost:8080/carShopService/hexiao/updateOrderStatus?ordId',
					data: {
						ordId: this.list[0].ordId
					},
					success: (res) => {
						console.log('当前状态为:' + res.data)
						if (res.statusCode === 200 && res.data === 1) {
							console.log('核销成功');
							this.flag2 = false;
							this.closePopup();

						} else {
							console.log('核销失败：', err);
						}
					}
				})


			},
		}
	};
</script>
<style lang="scss">
	.container {
		position: relative;

		.top {
			width: 720rpx;
			height: 160rpx;
			background-color: white;
			position: absolute;
			z-index: 1;
			border-radius: 30rpx;
			left: 15rpx;
			top: 90rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.input1 {
				color: #2E80F9;
				font-size: 30rpx;
				width: 200rpx;
			}

			.u-demo-block__content {
				width: 400rpx;
				font-size: 40rpx;
				border: 1rpx solid gray;
			}

		}

		.bottom {
			width: 720rpx;
			height: 900rpx;
			background-color: white;
			position: absolute;
			top: 280rpx;
			left: 15rpx;
			border-radius: 30rpx;
			display: flex;
			justify-content: center;
			flex-direction: column;
			align-items: center;

			.bottom1 {
				display: flex; // 启用Flexbox  
				align-items: center; // 垂直居中  
				justify-content: center; // 如果需要水平居中也可以添加这个，但在这个例子中可能不是必需的  
				margin-top: -30rpx;
				width: 680rpx;
				height: 100rpx;
				border-bottom: 1rpx solid gray;
				font-size: 18px;
				font-weight: 600;
			}

			.bottom2 {
				width: 680rpx;
				height: 350rpx;
				border-bottom: 1rpx solid gray;
				margin-top: 40rpx;
				display: flex;
				flex-direction: column;

			}

			.bottom3 {
				width: 680rpx;
				height: 350rpx;
				margin-top: 30rpx;
				display: flex;
				flex-direction: column;

			}


		}

		.status {
			position: absolute;
			background-color: #2E80F9;
			color: white;
			width: 500rpx;
			height: 80rpx;
			top: 1220rpx;
			left: 130rpx;
			border-radius: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 35rpx;
		}

		.status2 {
			position: absolute;
			background-color: #808080;
			color: white;
			width: 500rpx;
			height: 80rpx;
			top: 1220rpx;
			left: 130rpx;
			border-radius: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 35rpx;
		}

	}

	.title {
		font-size: 40rpx;
		font-weight: 600;
		margin-top: -22rpx;

	}

	.zw1 {
		margin-top: 70rpx;
		font-size: 40rpx;
	}

	.zw {
		margin-top: 9rpx;

	}

	.zws {
		margin-top: 9rpx;
		font-weight: 600;
	}



	.custom-dialog {
		/* 添加你的对话框样式 */
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 20px;
		border-radius: 10px;
		background-color: #fff;

		/* 其他样式... */
		.button-confirm {
			display: flex;


		}
	}

	.custom-dialog text {
		/* 文本样式 */
		margin-bottom: 10px;
		font-size: 40rpx;
		font-weight: 500;
		text-align: center;
	}

	.button-confirm1 {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 200rpx;
		height: 60rpx;
		border-radius: 30rpx;
		margin-right: 30rpx;
		margin-top: 20rpx;

	}

	.button-confirm2 {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		width: 200rpx;
		height: 60rpx;
		border-radius: 30rpx;
		margin-right: 30rpx;
		margin-top: 20rpx;
		color: white;
		background-color: #2E80F9;
	}
</style>